<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      :title="`${temp.goodsSpec}(${temp.gdStatus ? temp.gdStatus === 1 ? '重瓶' : temp.gdStatus === 2 ? '空瓶' : '' : ''})-盘点明细`"
      :visible.sync="visible"
      width="80%"
      :append-to-body="true"
      :destroy-on-close="true"
      @closed="reset"
      @close="reset"
    >
      <div class="page">
        <lb-table
          ref="lbTable"
          v-loading="$loadingPlugin.fetchData"
          border
          height="515px"
          element-loading-text="加载中"
          :column="tableData.column"
          :data="tableData.data"
          :total="tableData.total"
          custom-column
          pagination
          :immediate-fetch="false"
          @fetch="fetchData"
        />
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { invenStoreDetail } from '@/api'
  import { parseTime } from '@/utils'

  export default {
    components: {

    },
    data() {
      return {
        visible: false,
        temp: {},
        tableData: {
          data: [],
          total: 0,
          column: [
            {
              type: 'index'
            },
            {
              prop: 'gdCount',
              label: '数量',
              width: 105,
              render: (h, { row, $index }) => (
                <div>
                  { row.gdCount && <el-link type='danger' underline={false} size='mini' >{row.gdCount > 0 ? '+' + row.gdCount : row.gdCount}</el-link>}
                </div>
                )
            },
            {
              prop: 'reBillCode',
              label: '关联单号'
            },
            {
              prop: 'operator',
              label: '操作人'
            },
            {
              prop: 'operatorTime',
              label: '时间',
              render: (h, { row }) => (
              <span>
                {row.operatorTime && parseTime(row.operatorTime, '{y}-{m}-{d} {h}:{i}:{s}')}
              </span>
            )
            }
          ]
        }
      }
    },
    computed: {
    },
    watch: {

    },
    created() {

    },
    methods: {
      open(temp) {
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            this.temp = temp
            this.fetchData({ currentPage: 1, pageSize: 20 })
          }
        })
      },
      async fetchData({ currentPage, pageSize }) {
        const query = {
          currentPage,
          pageSize,
          params: {
            storeId: this.temp.storeId,
            specCode: this.temp.specCode,
            gdStatus: this.temp.gdStatus,
            profitType: 1
          }
        }
        const res = await invenStoreDetail(query)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      },
      reset() {

      }
    }
  }
</script>

<style lang='scss' scoped>

</style>
